import { DOCNAME, ip, port } from '../constants/index';
import { Query } from '../../gis/utils/Query';
export function getMap(hasControl, e) {
  const map = new ol.Map({
    target: 'map',
    layers: [gaodeVector, gaodeImage],
    view: new ol.View({
      projection: 'EPSG:4326',
      center: [114.3, 30.5],
      zoom: 13,
    }),
  });
  //创建一个Heatmap图层
  var vector = new ol.layer.Heatmap({
    //矢量数据源（读取本地的KML数据）
    source: new ol.source.Vector({
      url: '../../../gis/map/hotvector.kml',
      format: new ol.format.KML({
        extractStyles: false,
      }),
    }),
    //热点半径
    radius: 15,
    //模糊尺寸
    blur: 12,
  });
  map.addLayer(vector);
  vector.setVisible(false);
  const docLayer = new Zondy.Map.Doc('', DOCNAME, {
    ip,
    port,
  });
  map.addLayer(docLayer);

  if (!hasControl) {
    return map;
  }

  //实例化比例尺控件（ScaleLine）
  var scaleLineControl = new ol.control.ScaleLine({
    className: 'ol-scaleLineControl',
    //设置比例尺单位，degrees、imperial、us、nautical、metric（度量单位）
  });
  map.addControl(scaleLineControl);
  //实例化ZoomSlider控件并加载到地图容器中
  var zoomslider = new ol.control.ZoomSlider();
  map.addControl(zoomslider);
  //导航控件
  const nav = new ol.control.ZoomToExtent({
    extent: [112, 30, 120, 40], //左下坐标（112,30），右上坐标（120,40）
  });
  map.addControl(nav);
  //鼠标位置控件
  //实例化鼠标位置控件（MousePosition）
  var mousePositionControl = new ol.control.MousePosition({
    //坐标格式
    coordinateFormat: ol.coordinate.createStringXY(4),
    //地图投影坐标系（若未设置则输出为默认投影坐标系下的坐标）
    projection: 'EPSG:4326',
    //坐标信息显示样式类名，默认是'ol-mouse-position'
    className: 'custom-mouse-position',
    //显示鼠标位置信息的目标容器
    target: document.getElementById('mouse-position'),
    //未定义坐标的标记
    undefinedHTML: '&nbsp;',
  });
  map.addControl(mousePositionControl);

  const overviewMapControl = new ol.control.OverviewMap({
    /* 鹰眼控件样式  */
    className: 'ol-overviewmap ol-custom-overviewmap',
    layers: [gaodeVector],
    /* 鹰眼控件展开时功能按钮上的标识(网页的JS的字符编码) */
    collapseLabel: '\u00BB',
    /* 鹰眼控件折叠时功能按钮上的标识(网页的JS的字符编码) */
    label: '\u00AB',
    /* 初始为展开显示方式 */
    collapsed: false,
    view: new ol.View({
      projection: 'EPSG:4326',
    }),
  });
  map.addControl(overviewMapControl);

  return map;
}
/**
 *
 * @param {string} id 地图容器id
 *
 */
export function getSmallMap({ id }) {
  const map = new ol.Map({
    target: id,
    layers: [gaodeVector],
    view: new ol.View({
      projection: 'EPSG:4326',
      center: [114.38555, 30.5],
      zoom: 13,
    }),
  });
  const docLayer = new Zondy.Map.Doc('', DOCNAME, {
    ip,
    port,
  });
  map.addLayer(docLayer);
  let source = new ol.source.Vector({});
  let layer = new ol.layer.Vector({ source, title: 'draw' });
  map.addLayer(layer);
  return map;
}
